package org.mzyyn.qr.controller;

import jakarta.validation.Valid;
import org.checkerframework.checker.units.qual.A;
import org.mzyyn.qr.constants.AppletsApiUrlMapping;
import org.mzyyn.qr.dto.assistance.ReceivePrizeDTO;
import org.mzyyn.qr.service.AssistanceRecordService;
import org.mzyyn.qr.service.ShareService;
import org.qr.xiaocao.common.entity.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 分享表 前端控制器
 * </p>
 *
 * @author lipeng
 * @since 2024-09-04
 */
@RestController
public class ShareController {

    @Autowired
    ShareService shareService;

    @Autowired
    AssistanceRecordService assistanceRecordService;

    /**
     * 助力分享数据获取 :生成分享所需要的code：包括用户当前uuid等信息
     * @return
     */
    @PostMapping(AppletsApiUrlMapping.ASSISTANCE_SHARE)
    public BaseResult shareCode(){
        return BaseResult.ok(shareService.generateShareCode());
    }

    /**
     * 助力人员数据获取
     * @return
     */
    @PostMapping(AppletsApiUrlMapping.ASSISTANCE_RECORD)
    public BaseResult getAssistanceRecord( @Valid @RequestBody ReceivePrizeDTO receivePrizeDTO){
        return BaseResult.ok(shareService.getAssistanceRecord(receivePrizeDTO.getCode()));
    }

    /**
     * 助力人员总数
     * @return
     */
    @PostMapping(AppletsApiUrlMapping.ASSISTANCE_COUNT)
    public BaseResult getAssistanceCount( @Valid @RequestBody ReceivePrizeDTO receivePrizeDTO){
        return BaseResult.ok(assistanceRecordService.assistancePeopleCount(receivePrizeDTO.getCode()));
    }

    /**
     * 领取奖品
     * @return
     */
    @PostMapping(AppletsApiUrlMapping.ASSISTANCE_RECEIVE_PRIZE)
    public BaseResult receivePrize(
            @Valid @RequestBody ReceivePrizeDTO receivePrizeDTO
    ){
        return BaseResult.ok(shareService.receivePrize(receivePrizeDTO));
    }
}
